//处理提交表单返回的数据
var successCallback = function (data) {
    var tip = '';
    // $('#imgcode').trigger('click');
    switch (data.status) {
        case 200:
            tip = '登录成功,正在跳转...';
            window.location.reload();
            break;
    }
    tooltipWrong($('#requestSubmit'), tip, 3);
};


var errorCallback = function (data) {
    if (typeof (data.responseJSON) == "undefined") {
        tooltipWrong($('#requestSubmit'), '系统内部错误', 3);
    } else {
        switch (data.responseJSON.status) {
            case 205:
                tip = '参数信息不完整';
                break;
            case 206:
                tip = '参数长度错误';
                break;
            case 207:
                tip = '密码格式错误错误';
                break;
            case 208:
                tip = '验证码错误';
                break;
            case 209:
                tip = '用户不存在';
                break;
            case 301:
                tip = '用户信息不存在';
                break;
            case 210:
                tip = '密码错误';
                break;

            default:
                tip = "未知错误" + data.status;
        }
        $('#imgcode').trigger('click');
        tip = data.responseJSON.info;
        tooltipWrong($('#requestSubmit'), tip, 3);

    }
};

$(function () {
    var passwordResult = false;
    var newPasswordResult = false;
    var confirmPasswordResult = false;
    $('#requestPassword').on('blur', function (e) {
        e.preventDefault();
        switch (validateData($(this).val(), /^.{6,}$/)) {
            case 0:
                passwordResult = false;
                tooltipWrong($(this), "密码为6位以上字符", 3);
                break;
            case -1:
                passwordResult = false;
                tooltipWrong($(this), "密码不能为空", 3);
                break;
            case 1:
                passwordResult = true;
                break;
            default:
                tooltipWrong($(this), "数据验证出现问题", 3);
        }
    });
    $('#requestNewPassword').on('blur', function (e) {
        e.preventDefault();
        switch (validateData($(this).val(), /^.{6,}$/)) {
            case 0:
                newPasswordResult = false;
                tooltipWrong($(this), "密码为6位以上字符", 3);
                break;
            case -1:
                newPasswordResult = false;
                tooltipWrong($(this), "密码不能为空", 3);
                break;
            case 1:
                newPasswordResult = true;
                break;
            default:
                tooltipWrong($(this), "数据验证出现问题", 3);
        }
    });
    $('#requestConfirmNew').on('blur', function (e) {
        e.preventDefault();
        switch (validateData($(this).val(), /^.{6,}$/)) {
            case 0:
                confirmPasswordResult = false;
                tooltipWrong($(this), "密码为6位以上字符", 3);
                break;
            case -1:
                confirmPasswordResult = false;
                tooltipWrong($(this), "密码不能为空", 3);
                break;
            case 1:
                confirmPasswordResult = true;
                break;
            default:
                tooltipWrong($(this), "数据验证出现问题", 3);
        }
    });
    $('#requestVcode').on('blur', function (e) {
        e.preventDefault();
        switch (validateData($(this).val(), /^\w{4}$/)) {
            case 0:
                vcodeResult = false;
                tooltipWrong($('#refreshCode'), "验证码为4位字符", 3);
                break;
            case -1:
                vcodeResult = false;
                tooltipWrong($('#refreshCode'), "验证码不能为空", 3);
                break;
            case 1:
                vcodeResult = true;
                break;
            default:
                tooltipWrong($(this), "数据验证出现问题", 3);
        }
    });
    $('#requestSubmit').on('click', function (e) {
        e.preventDefault();
        $('#requestPassword').blur();
        $('#requestNewPassword').blur();
        $('#requestConfirmNew').blur();
        $('#requestVcode').blur();
        if (passwordResult && newPasswordResult && confirmPasswordResult) {
            var params = new Object();
            params.oldPassword = $.md5($('#requestPassword').val());
            params.newPassword = $.md5($('#requestNewPassword').val());
            ajaxRequest('/Home/Admin/updatePassword', params, 'post', successCallback, errorCallback);
        }
    });
});